<template>
  <view class="operation-records">
    <!-- 自定义导航栏 -->
    <cu-custom bgColor="bg-gradual-blue" :isBack="true">
      <block slot="content">
        <text class="nav-title">成品操作记录</text>
      </block>
      <block slot="right">
        <view class="nav-right" @click="openFilterModal">
          <text
            class="cuIcon-filter"
            :class="{ 'filter-active': hasActiveFilters }"
          ></text>
          <text
            class="filter-text"
            :class="{ 'filter-active': hasActiveFilters }"
            >筛选</text
          >
          <view v-if="hasActiveFilters" class="filter-dot"></view>
        </view>
      </block>
    </cu-custom>

    <!-- Tab切换 -->
    <view class="tab-container">
      <view class="tab-list">
        <view
          class="tab-item"
          :class="{ active: activeTab === 'inbound' }"
          @click="switchTab('inbound')"
        >
          <text class="tab-text">入库记录</text>
        </view>
        <view
          class="tab-item"
          :class="{ active: activeTab === 'outbound' }"
          @click="switchTab('outbound')"
        >
          <text class="tab-text">出库记录</text>
        </view>
      </view>
    </view>

    <!-- 记录列表 -->
    <view class="records-container">
      <!-- 入库记录 -->
      <view v-if="activeTab === 'inbound'" class="record-list">
        <view v-if="loading" class="loading-container">
          <uni-load-more
            status="loading"
            content-text="{ contentText: { contentdown: '上拉显示更多', contentrefresh: '正在加载...', contentnomore: '没有更多数据了' } }"
          ></uni-load-more>
        </view>
        <view v-else-if="inboundRecords.length === 0" class="empty-container">
          <view class="empty-icon">
            <text class="iconfont icon-empty"></text>
          </view>
          <text class="empty-text">暂无入库操作记录</text>
        </view>
        <view v-else>
          <view
            v-for="record in inboundRecords"
            :key="record.id"
            class="record-item inbound-item"
            @click="viewRecordDetail(record)"
          >
            <view class="record-header">
              <view class="record-title">
                <view class="order-no">{{
                  record.relatedDocNo || record.orderNo || "无关联单号"
                }}</view>
                <view class="record-status inbound-status">
                  {{ record.operationTypeText }}
                </view>
              </view>
              <view class="record-time">{{
                formatTime(record.createTime)
              }}</view>
            </view>
            <view class="record-content">
              <view class="record-info">
                <view class="info-item" v-if="record.orderNo">
                  <text class="info-label">订单号:</text>
                  <text class="info-value">{{ record.orderNo }}</text>
                </view>
                <view class="info-item" v-if="record.operationQuantity">
                  <text class="info-label">数量:</text>
                  <text class="info-value inbound-qty"
                    >+{{ record.operationQuantity }}</text
                  >
                </view>
                <view class="info-item" v-if="record.operatorName">
                  <text class="info-label">操作人:</text>
                  <text class="info-value">{{ record.operatorName }}</text>
                </view>
              </view>
            </view>

            <!-- 用户操作详情展开面板 -->
            <view
              v-if="isRecordExpanded(record.id)"
              class="user-operations-panel"
            >
              <view class="panel-header">
                <text class="panel-title">操作明细</text>
                <view
                  class="inbound-type-tag"
                  :class="[getOperationTypeClass(record.operationType)]"
                >
                  <text class="type-text">{{ record.operationTypeText }}</text>
                </view>
              </view>
              <view class="operations-list">
                <view class="operation-item">
                  <view class="item-content">
                    <view class="material-details">
                      <view class="detail-row" v-if="record.orderNo">
                        <text class="label">订单号</text>
                        <text class="value">{{ record.orderNo }}</text>
                      </view>
                      <view class="detail-row" v-if="record.relatedDocNo">
                        <text class="label">关联单号</text>
                        <text class="value">{{ record.relatedDocNo }}</text>
                      </view>
                      <view class="detail-row" v-if="record.operationReason">
                        <text class="label">操作原因</text>
                        <text class="value">{{ record.operationReason }}</text>
                      </view>
                      <view
                        class="detail-row"
                        v-if="record.beforeQuantity !== undefined"
                      >
                        <text class="label">操作前数量</text>
                        <text class="value">{{ record.beforeQuantity }}</text>
                      </view>
                      <view
                        class="detail-row"
                        v-if="record.afterQuantity !== undefined"
                      >
                        <text class="label">操作后数量</text>
                        <text class="value">{{ record.afterQuantity }}</text>
                      </view>
                    </view>

                    <view class="quantity-section">
                      <view class="quantity-item actual">
                        <text class="qty-label">操作数量</text>
                        <text class="qty-value inbound-qty"
                          >+{{ record.operationQuantity }}</text
                        >
                      </view>
                    </view>
                  </view>
                </view>
              </view>
            </view>

            <!-- 展开/收起按钮 -->
            <view
              class="expand-button"
              @click.stop="toggleRecordExpand(record.id)"
            >
              <text class="expand-text">{{
                isRecordExpanded(record.id) ? "收起详情" : "查看我的操作"
              }}</text>
              <text
                class="expand-icon"
                :class="{ expanded: isRecordExpanded(record.id) }"
                >▼</text
              >
            </view>
          </view>
        </view>
      </view>

      <!-- 出库记录 -->
      <view v-if="activeTab === 'outbound'" class="record-list">
        <view v-if="loading" class="loading-container">
          <uni-load-more
            status="loading"
            content-text="{ contentText: { contentdown: '上拉显示更多', contentrefresh: '正在加载...', contentnomore: '没有更多数据了' } }"
          ></uni-load-more>
        </view>
        <view v-else-if="outboundRecords.length === 0" class="empty-container">
          <view class="empty-icon">
            <text class="iconfont icon-empty"></text>
          </view>
          <text class="empty-text">暂无出库操作记录</text>
        </view>
        <view v-else>
          <view
            v-for="record in outboundRecords"
            :key="record.id"
            class="record-item outbound-item"
            @click="viewRecordDetail(record)"
          >
            <view class="record-header">
              <view class="record-title">
                <view class="order-no">{{
                  record.relatedDocNo || record.orderNo || "无关联单号"
                }}</view>
                <view class="record-status outbound-status">
                  {{ record.operationTypeText }}
                </view>
              </view>
              <view class="record-time">{{
                formatTime(record.createTime)
              }}</view>
            </view>
            <view class="record-content">
              <view class="record-info">
                <view class="info-item" v-if="record.orderNo">
                  <text class="info-label">订单号:</text>
                  <text class="info-value">{{ record.orderNo }}</text>
                </view>
                <view class="info-item" v-if="record.operationQuantity">
                  <text class="info-label">数量:</text>
                  <text class="info-value outbound-qty"
                    >-{{ record.operationQuantity }}</text
                  >
                </view>
                <view class="info-item" v-if="record.operatorName">
                  <text class="info-label">操作人:</text>
                  <text class="info-value">{{ record.operatorName }}</text>
                </view>
              </view>
            </view>

            <!-- 用户操作详情展开面板 -->
            <view
              v-if="isRecordExpanded(record.id)"
              class="user-operations-panel"
            >
              <view class="panel-header">
                <text class="panel-title">操作明细</text>
                <view
                  class="outbound-type-tag"
                  :class="[getOperationTypeClass(record.operationType)]"
                >
                  <text class="type-text">{{ record.operationTypeText }}</text>
                </view>
              </view>
              <view class="operations-list">
                <view class="operation-item">
                  <view class="item-content">
                    <view class="material-details">
                      <view class="detail-row" v-if="record.orderNo">
                        <text class="label">订单号</text>
                        <text class="value">{{ record.orderNo }}</text>
                      </view>
                      <view class="detail-row" v-if="record.relatedDocNo">
                        <text class="label">关联单号</text>
                        <text class="value">{{ record.relatedDocNo }}</text>
                      </view>
                      <view class="detail-row" v-if="record.operationReason">
                        <text class="label">操作原因</text>
                        <text class="value">{{ record.operationReason }}</text>
                      </view>
                      <view
                        class="detail-row"
                        v-if="record.beforeQuantity !== undefined"
                      >
                        <text class="label">操作前数量</text>
                        <text class="value">{{ record.beforeQuantity }}</text>
                      </view>
                      <view
                        class="detail-row"
                        v-if="record.afterQuantity !== undefined"
                      >
                        <text class="label">操作后数量</text>
                        <text class="value">{{ record.afterQuantity }}</text>
                      </view>
                    </view>

                    <view class="quantity-section">
                      <view class="quantity-item actual">
                        <text class="qty-label">操作数量</text>
                        <text class="qty-value outbound-qty"
                          >-{{ record.operationQuantity }}</text
                        >
                      </view>
                    </view>
                  </view>
                </view>
              </view>
            </view>

            <!-- 展开/收起按钮 -->
            <view
              class="expand-button"
              @click.stop="toggleRecordExpand(record.id)"
            >
              <text class="expand-text">{{
                isRecordExpanded(record.id) ? "收起详情" : "查看我的操作"
              }}</text>
              <text
                class="expand-icon"
                :class="{ expanded: isRecordExpanded(record.id) }"
                >▼</text
              >
            </view>
          </view>
        </view>
      </view>
    </view>

    <!-- 加载更多 -->
    <view class="load-more-container">
      <uni-load-more
        :status="loadMoreStatus"
        :content-text="{
          contentdown: '上拉加载更多',
          contentrefresh: '加载中...',
          contentnomore: '没有更多数据了',
        }"
        @clickLoadMore="loadMore"
      ></uni-load-more>
    </view>

    <!-- 筛选弹窗 -->
    <view
      class="filter-modal"
      v-if="showFilterModal"
      @click="showFilterModal = false"
    >
      <view class="filter-content" @click.stop>
        <view class="filter-header">
          <text class="filter-title">筛选条件</text>
          <view class="close-btn" @click="showFilterModal = false">
            <text class="cuIcon-close"></text>
          </view>
        </view>

        <scroll-view class="filter-body" scroll-y="true">
          <!-- 搜索关键字 -->
          <view class="filter-section">
            <view class="group-title">搜索关键字</view>
            <input
              class="input-field"
              placeholder="请输入订单号或关联单号"
              v-model="filterForm.keyword"
            />
          </view>

          <!-- 操作时间范围 -->
          <view class="filter-section">
            <view class="group-title">操作时间</view>
            <view class="time-range">
              <picker
                mode="date"
                :value="filterForm.startTime"
                @change="onStartTimeChange"
              >
                <view class="time-picker">
                  {{ filterForm.startTime || "开始时间" }}
                </view>
              </picker>
              <text class="time-separator">至</text>
              <picker
                mode="date"
                :value="filterForm.endTime"
                @change="onEndTimeChange"
              >
                <view class="time-picker">
                  {{ filterForm.endTime || "结束时间" }}
                </view>
              </picker>
            </view>
          </view>
        </scroll-view>

        <view class="filter-footer">
          <view class="filter-btn reset" @click="resetFilter">重置</view>
          <view class="filter-btn confirm" @click="applyFilter">确定</view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import { finishedGoodsInventoryLog } from "@/api/wms/finishedGoods.js";

export default {
  name: "FinishedGoodsOperationRecords",
  data() {
    return {
      activeTab: "inbound", // 当前激活的标签页
      inboundRecords: [], // 入库记录列表
      outboundRecords: [], // 出库记录列表
      allRecords: [], // 所有记录列表
      loading: false, // 加载状态
      loadMoreStatus: "more", // 加载更多状态: more, loading, noMore
      pageInfo: {
        current: 1,
        size: 20,
        total: 0,
      },
      expandedRecords: new Set(), // 展开的记录ID集合

      // 筛选相关
      showFilterModal: false,
      filterForm: {
        keyword: "", // 搜索关键字（订单号或关联单号）
        operationType: [], // 操作类型筛选
        operatorName: "", // 操作员姓名
        startTime: "", // 开始时间
        endTime: "", // 结束时间
      },

      // 操作类型选项
      operationTypes: [
        { label: "入库", value: 1 },
        { label: "出库", value: 2 },
        { label: "调整", value: 3 },
        { label: "预留", value: 4 },
        { label: "释放", value: 5 },
      ],
    };
  },
  onLoad() {
    this.loadRecords();
  },
  onShow() {
    // 页面显示时刷新数据
    this.refreshRecords();
  },
  onReachBottom() {
    this.loadMore();
  },
  methods: {
    // 切换tab
    switchTab(tab) {
      if (this.activeTab === tab) return;
      this.activeTab = tab;
      this.filterRecordsByTab();
    },

    // 根据标签页筛选记录
    filterRecordsByTab() {
      if (this.activeTab === "inbound") {
        this.inboundRecords = this.allRecords.filter(
          (record) => record.operationType === 1
        );
      } else {
        this.outboundRecords = this.allRecords.filter(
          (record) => record.operationType === 2
        );
      }
    },

    // 加载记录
    async loadRecords(refresh = false) {
      if (this.loading) return;

      if (refresh) {
        this.pageInfo.current = 1;
        this.allRecords = [];
        this.inboundRecords = [];
        this.outboundRecords = [];
      }

      this.loading = true;

      try {
        // 构建筛选参数
        const params = {
          pageNo: this.pageInfo.current,
          pageSize: this.pageInfo.size,
        };

        // 添加筛选条件
        if (this.filterForm.keyword) {
          params.keyword = this.filterForm.keyword;
        }
        if (this.filterForm.operationType.length > 0) {
          params.operationType = this.filterForm.operationType[0]; // API只支持单个操作类型
        }

        const response = await finishedGoodsInventoryLog.getRecords(params);

        if (response.data.success) {
          const records = response.data.result.records || [];

          // 处理数据，添加操作类型文本
          const processedRecords = records.map((record) => ({
            ...record,
            operationTypeText: this.getOperationTypeText(record.operationType),
          }));

          if (refresh) {
            this.allRecords = processedRecords;
          } else {
            this.allRecords = [...this.allRecords, ...processedRecords];
          }

          this.pageInfo.total = response.data.result.total || 0;
          this.pageInfo.current++;

          // 根据标签页筛选记录
          this.filterRecordsByTab();

          // 更新加载更多状态
          if (this.allRecords.length >= this.pageInfo.total) {
            this.loadMoreStatus = "noMore";
          } else {
            this.loadMoreStatus = "more";
          }
        } else {
          uni.showToast({
            title: response.data.message || "加载失败",
            icon: "none",
          });
        }
      } catch (error) {
        console.error("加载成品操作记录失败:", error);
        uni.showToast({
          title: "网络错误",
          icon: "none",
        });
      } finally {
        this.loading = false;
      }
    },

    // 刷新记录
    refreshRecords() {
      this.loadRecords(true);
    },

    // 加载更多
    loadMore() {
      if (this.loadMoreStatus !== "more") return;
      this.loadRecords();
    },

    // 查看记录详情
    viewRecordDetail(record) {
      // 可以根据需要跳转到详情页面
      console.log("查看记录详情:", record);
    },

    // 格式化时间
    formatTime(time) {
      if (!time) return "";
      const date = new Date(time);
      const now = new Date();
      const diff = now.getTime() - date.getTime();

      if (diff < 60000) {
        // 1分钟内
        return "刚刚";
      } else if (diff < 3600000) {
        // 1小时内
        return Math.floor(diff / 60000) + "分钟前";
      } else if (diff < 86400000) {
        // 24小时内
        return Math.floor(diff / 3600000) + "小时前";
      } else {
        return (
          date.toLocaleDateString() +
          " " +
          date.toLocaleTimeString().slice(0, 5)
        );
      }
    },

    // 获取操作类型文本
    getOperationTypeText(operationType) {
      const typeMap = {
        1: "入库",
        2: "出库",
        3: "调整",
        4: "预留",
        5: "释放",
      };
      return typeMap[operationType] || "未知操作";
    },

    // 打开筛选弹窗
    openFilterModal() {
      this.showFilterModal = true;
    },

    // 切换操作类型筛选
    toggleOperationType(typeValue) {
      const index = this.filterForm.operationType.indexOf(typeValue);
      if (index > -1) {
        this.filterForm.operationType.splice(index, 1);
      } else {
        this.filterForm.operationType.push(typeValue);
      }
    },

    // 重置筛选
    resetFilter() {
      this.filterForm = {
        keyword: "",
        operationType: [],
        operatorName: "",
        startTime: "",
        endTime: "",
      };
    },

    // 应用筛选
    applyFilter() {
      this.showFilterModal = false;
      this.refreshRecords();
    },

    // 切换记录展开状态
    toggleRecordExpand(recordId) {
      if (this.expandedRecords.has(recordId)) {
        this.expandedRecords.delete(recordId);
      } else {
        this.expandedRecords.add(recordId);
      }
      // 触发响应式更新
      this.$forceUpdate();
    },

    // 检查记录是否展开
    isRecordExpanded(recordId) {
      return this.expandedRecords.has(recordId);
    },

    // 检查是否有激活的筛选条件
    hasActiveFilters() {
      return (
        this.filterForm.keyword ||
        this.filterForm.operationType.length > 0 ||
        this.filterForm.operatorName ||
        this.filterForm.startTime ||
        this.filterForm.endTime
      );
    },

    // 获取操作类型样式类
    getOperationTypeClass(operationType) {
      const typeClassMap = {
        1: "inbound-type", // 入库
        2: "outbound-type", // 出库
        3: "adjust-type", // 调整
        4: "reserve-type", // 预留
        5: "release-type", // 释放
      };
      return typeClassMap[operationType] || "default-type";
    },

    // 开始时间选择
    onStartTimeChange(e) {
      this.filterForm.startTime = e.detail.value;
    },

    // 结束时间选择
    onEndTimeChange(e) {
      this.filterForm.endTime = e.detail.value;
    },
  },
};
</script>

<style lang="scss" scoped>
.operation-records {
  background: #f5f7fa;
  min-height: 100vh;
}

.nav-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 24rpx;
  text-align: center;

  .nav-title {
    font-size: 36rpx;
    font-weight: bold;
  }
}

.tab-container {
  background: white;
  padding: 0 24rpx;
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
}

.tab-list {
  display: flex;
  align-items: center;
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32rpx 0;
  position: relative;
  transition: all 0.3s ease;

  &.active {
    .tab-icon {
      background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
      transform: scale(1.1);
    }

    .tab-text {
      color: #1890ff;
      font-weight: bold;
    }

    &::after {
      content: "";
      position: absolute;
      bottom: 0;
      left: 50%;
      transform: translateX(-50%);
      width: 60rpx;
      height: 6rpx;
      background: linear-gradient(90deg, #4facfe 0%, #00f2fe 100%);
      border-radius: 3rpx;
    }
  }

  .tab-icon {
    width: 80rpx;
    height: 80rpx;
    background: #f0f2f5;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16rpx;
    transition: all 0.3s ease;

    .iconfont {
      font-size: 36rpx;
      color: white;
    }
  }

  .tab-text {
    font-size: 28rpx;
    color: #666;
    transition: all 0.3s ease;
  }
}

.records-container {
  padding: 24rpx;
}

.record-list {
  .record-item {
    background: white;
    border-radius: 20rpx;
    margin-bottom: 24rpx;
    padding: 32rpx;
    box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.06);
    border: 2rpx solid transparent;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;

    &::before {
      content: "";
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      height: 6rpx;
    }

    &.inbound-item::before {
      background: linear-gradient(90deg, #52c41a 0%, #389e0d 100%);
    }

    &.outbound-item::before {
      background: linear-gradient(90deg, #fa8c16 0%, #d46b08 100%);
    }

    &:active {
      transform: scale(0.98);
      box-shadow: 0 12rpx 32rpx rgba(0, 0, 0, 0.12);
    }
  }
}

.record-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24rpx;

  .record-title {
    flex: 1;

    .order-no {
      font-size: 32rpx;
      font-weight: bold;
      color: #262626;
      margin-bottom: 8rpx;
    }

    .record-status {
      display: inline-block;
      padding: 8rpx 16rpx;
      border-radius: 20rpx;
      font-size: 22rpx;
      font-weight: 500;

      // 入库单状态样式
      &.status-0 {
        background: #fff7e6;
        color: #fa8c16;
        border: 1rpx solid #ffd591;
      }

      &.status-1 {
        background: #f6ffed;
        color: #52c41a;
        border: 1rpx solid #b7eb8f;
      }

      &.status-2 {
        background: #e6f7ff;
        color: #1890ff;
        border: 1rpx solid #91d5ff;
      }

      &.status-3 {
        background: #f6ffed;
        color: #52c41a;
        border: 1rpx solid #b7eb8f;
      }

      &.status-4 {
        background: #fff2f0;
        color: #ff4d4f;
        border: 1rpx solid #ffccc7;
      }

      // 出库单状态样式 - status-5 部分出库
      &.status-5 {
        background: #e6f7ff;
        color: #1890ff;
        border: 1rpx solid #91d5ff;
      }
    }
  }

  .record-time {
    font-size: 24rpx;
    color: #8c8c8c;
    white-space: nowrap;
  }
}

.record-content {
  .record-info {
    margin-bottom: 20rpx;

    .info-item {
      display: flex;
      align-items: center;
      margin-bottom: 12rpx;

      &:last-child {
        margin-bottom: 0;
      }

      .info-label {
        font-size: 26rpx;
        color: #8c8c8c;
        margin-right: 16rpx;
        min-width: 120rpx;
      }

      .info-value {
        font-size: 26rpx;
        color: #262626;
        flex: 1;
      }
    }
  }

  .record-details {
    background: #fafbfc;
    border-radius: 12rpx;
    padding: 20rpx;

    .detail-summary {
      font-size: 24rpx;
      color: #8c8c8c;
      margin-bottom: 16rpx;
    }

    .detail-list {
      .detail-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 8rpx;

        &:last-child {
          margin-bottom: 0;
        }

        .material-name {
          font-size: 26rpx;
          color: #262626;
          flex: 1;
          margin-right: 16rpx;
        }

        .material-quantity {
          font-size: 26rpx;
          color: #1890ff;
          font-weight: 500;
        }
      }

      .more-details {
        font-size: 24rpx;
        color: #8c8c8c;
        text-align: center;
        margin-top: 12rpx;
        padding-top: 12rpx;
        border-top: 1rpx solid #f0f0f0;
      }
    }
  }
}

.loading-container,
.empty-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 120rpx 0;
}

.empty-container {
  .empty-icon {
    width: 120rpx;
    height: 120rpx;
    background: #f5f5f5;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24rpx;

    .iconfont {
      font-size: 48rpx;
      color: #bfbfbf;
    }
  }

  .empty-text {
    font-size: 28rpx;
    color: #8c8c8c;
  }
}

.load-more-container {
  padding: 24rpx;
}

// 用户操作详情面板样式
.user-operations-panel {
  margin-top: 20rpx;
  background: #ffffff;
  border-radius: 16rpx;
  padding: 24rpx;
  border: 1rpx solid #e9ecef;
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);

  .panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20rpx;
    padding-bottom: 16rpx;
    border-bottom: 1rpx solid #f0f0f0;

    .panel-title {
      font-size: 30rpx;
      font-weight: 600;
      color: #2c3e50;
    }

    // 入库类型标签样式
    .inbound-type-tag,
    .outbound-type-tag {
      padding: 6rpx 12rpx;
      border-radius: 20rpx;
      font-size: 22rpx;
      font-weight: 500;

      .type-text {
        color: white;
      }

      // 入库操作
      &.inbound-type {
        background: linear-gradient(135deg, #52c41a 0%, #389e0d 100%);
      }

      // 出库操作
      &.outbound-type {
        background: linear-gradient(135deg, #fa8c16 0%, #d46b08 100%);
      }

      // 调整操作
      &.adjust-type {
        background: linear-gradient(135deg, #1890ff 0%, #096dd9 100%);
      }

      // 预留操作
      &.reserve-type {
        background: linear-gradient(135deg, #722ed1 0%, #531dab 100%);
      }

      // 释放操作
      &.release-type {
        background: linear-gradient(135deg, #13c2c2 0%, #08979c 100%);
      }

      // 默认类型
      &.default-type {
        background: linear-gradient(135deg, #8c8c8c 0%, #595959 100%);
      }
    }
  }

  .operations-list {
    .operation-item {
      background: #fafbfc;
      border-radius: 12rpx;
      padding: 20rpx;
      margin-bottom: 16rpx;
      border: 1rpx solid #f0f0f0;
      transition: all 0.3s ease;

      &:last-child {
        margin-bottom: 0;
      }

      &:active {
        background: #f5f6fa;
        transform: scale(0.98);
      }

      .item-header {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        margin-bottom: 16rpx;

        .material-name {
          font-size: 30rpx;
          color: #2c3e50;
          font-weight: 600;
          flex: 1;
          margin-right: 16rpx;
          line-height: 1.4;
        }

        .operation-time {
          font-size: 24rpx;
          color: #7f8c8d;
          white-space: nowrap;
        }
      }

      .item-content {
        display: flex;
        justify-content: space-between;
        margin-bottom: 16rpx;

        .material-details {
          flex: 1;
          margin-right: 20rpx;

          .detail-row {
            display: flex;
            align-items: center;
            margin-bottom: 8rpx;

            &:last-child {
              margin-bottom: 0;
            }

            .label {
              font-size: 24rpx;
              color: #95a5a6;
              min-width: 60rpx;
              margin-right: 12rpx;
            }

            .value {
              font-size: 26rpx;
              color: #34495e;
              flex: 1;
            }
          }
        }

        .quantity-section {
          display: flex;
          flex-direction: column;
          min-width: 120rpx;

          .quantity-item {
            display: flex;
            align-items: center;
            justify-content: flex-end;
            margin-bottom: 8rpx;
            padding: 6rpx 12rpx;
            border-radius: 8rpx;

            &:last-child {
              margin-bottom: 0;
            }

            &.plan {
              background: #e8f4fd;
            }

            &.actual {
              background: #e8f5e8;
            }

            &.allocated {
              background: #fff3cd;
            }

            &.remaining {
              background: #f8d7da;
            }

            .qty-label {
              font-size: 22rpx;
              color: #7f8c8d;
              margin-right: 8rpx;
            }

            .qty-value {
              font-size: 26rpx;
              font-weight: 600;
              margin-right: 4rpx;

              .plan & {
                color: #3498db;
              }

              .actual & {
                color: #27ae60;
              }

              .allocated & {
                color: #856404;
              }

              .remaining & {
                color: #721c24;
              }
            }

            .qty-unit {
              font-size: 22rpx;
              color: #95a5a6;
            }
          }
        }
      }

      .item-footer {
        border-top: 1rpx solid #ecf0f1;
        padding-top: 12rpx;

        .location-row,
        .remark-row {
          display: flex;
          align-items: flex-start;
          margin-bottom: 8rpx;

          &:last-child {
            margin-bottom: 0;
          }
        }

        .location-icon,
        .remark-icon {
          font-size: 24rpx;
          margin-right: 8rpx;
          margin-top: 2rpx;
        }

        .location-text,
        .remark-text {
          font-size: 24rpx;
          color: #7f8c8d;
          flex: 1;
          line-height: 1.4;
        }

        .remark-text {
          font-style: italic;
        }
      }
    }

    .no-operations {
      text-align: center;
      padding: 32rpx 0;
      color: #6c757d;
      font-size: 26rpx;
    }
  }
}

// 展开按钮样式
.expand-button {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 16rpx;
  padding: 12rpx 0;
  background: #f8f9fa;
  border-radius: 8rpx;
  border: 1rpx solid #e9ecef;
  transition: all 0.3s ease;

  &:active {
    background: #e9ecef;
  }

  .expand-text {
    font-size: 24rpx;
    color: #6c757d;
    margin-right: 8rpx;
  }

  .expand-icon {
    font-size: 20rpx;
    color: #6c757d;
    transition: transform 0.3s ease;

    &.expanded {
      transform: rotate(180deg);
    }
  }
}

// 自定义导航栏右侧按钮样式
.nav-right {
  display: flex;
  align-items: center;
  padding: 8rpx 16rpx;
  border-radius: 20rpx;
  background: rgba(255, 255, 255, 0.2);
  transition: all 0.3s ease;

  &:active {
    background: rgba(255, 255, 255, 0.3);
  }

  .cuIcon-filter {
    font-size: 28rpx;
    margin-right: 6rpx;
  }

  .filter-text {
    font-size: 24rpx;
  }
}

.nav-right {
  display: flex;
  align-items: center;
  color: white;
  font-size: 28rpx;
  position: relative;

  .cuIcon-filter {
    margin-right: 8rpx;
    font-size: 32rpx;
    transition: all 0.3s ease;

    &.filter-active {
      color: #ffd700;
      transform: scale(1.1);
    }
  }

  .filter-text {
    font-size: 28rpx;
    transition: all 0.3s ease;

    &.filter-active {
      color: #ffd700;
      font-weight: bold;
    }
  }

  .filter-dot {
    position: absolute;
    top: -4rpx;
    right: -4rpx;
    width: 16rpx;
    height: 16rpx;
    background: #ff4d4f;
    border-radius: 50%;
    border: 2rpx solid white;
  }
}

// 筛选弹窗样式
.filter-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 9999;
  display: flex;
  align-items: flex-end;

  .filter-content {
    width: 100%;
    max-height: 80vh;
    background: #ffffff;
    border-radius: 20rpx 20rpx 0 0;
    display: flex;
    flex-direction: column;

    .filter-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 32rpx;
      border-bottom: 1rpx solid #f0f0f0;

      .filter-title {
        font-size: 32rpx;
        font-weight: 600;
        color: #333333;
      }

      .close-btn {
        width: 60rpx;
        height: 60rpx;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #999999;
        font-size: 32rpx;
      }
    }

    .filter-body {
      flex: 1;
      padding: 0 32rpx;
      max-height: 60vh;

      .filter-section {
        margin-bottom: 40rpx;

        .group-title {
          font-size: 28rpx;
          font-weight: 600;
          color: #333333;
          margin-bottom: 20rpx;
        }

        .input-field {
          width: 100%;
          height: 80rpx;
          padding: 0 24rpx;
          border: 1rpx solid #e0e0e0;
          border-radius: 12rpx;
          font-size: 28rpx;
          color: #333333;
          background: #ffffff;

          &:focus {
            border-color: #007aff;
          }
        }

        .checkbox-group {
          display: flex;
          flex-wrap: wrap;
          gap: 20rpx;

          .checkbox-item {
            padding: 16rpx 24rpx;
            border: 1rpx solid #e0e0e0;
            border-radius: 40rpx;
            background: #ffffff;
            transition: all 0.3s ease;

            &.checked {
              background: #007aff;
              border-color: #007aff;

              .checkbox-text {
                color: #ffffff;
              }
            }

            .checkbox-text {
              font-size: 26rpx;
              color: #666666;
              transition: color 0.3s ease;
            }
          }
        }
      }

      .time-range {
        display: flex;
        align-items: center;
        gap: 16rpx;

        .time-picker {
          flex: 1;
          height: 80rpx;
          padding: 0 24rpx;
          border: 1rpx solid #e0e0e0;
          border-radius: 12rpx;
          display: flex;
          align-items: center;
          font-size: 28rpx;
          color: #333333;
          background: #ffffff;
        }

        .time-separator {
          font-size: 26rpx;
          color: #666666;
        }
      }
    }

    .filter-footer {
      display: flex;
      padding: 32rpx;
      gap: 24rpx;
      border-top: 1rpx solid #f0f0f0;

      .filter-btn {
        flex: 1;
        height: 88rpx;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 12rpx;
        font-size: 30rpx;
        font-weight: 600;
        transition: all 0.3s ease;

        &.reset {
          background: #f5f5f5;
          color: #666666;

          &:active {
            background: #e0e0e0;
          }
        }

        &.confirm {
          background: #007aff;
          color: #ffffff;

          &:active {
            background: #0056cc;
          }
        }
      }
    }
  }
}
</style>
